package talk.rongyun;


import android.net.Uri;

import talk.Bean.MyUser;
import talk.Data.Constant;


import io.rong.imkit.RongIM;
import io.rong.imlib.model.UserInfo;

/**
 * Created by debby on 2018/4/8.
 * 描述:用户处理
 */

public class UserUtil {

    public static void setUser() {
        RongIM.setUserInfoProvider(new RongIM.UserInfoProvider() {
            @Override
            public UserInfo getUserInfo(String userId) {
                return findUserById(userId);
            }
        }, true);
    }


    private static UserInfo findUserById(String userId) {
        MyUser users = Constant.user;
        if (userId != users.getSinfo().getUid()) {
            for (MyUser.FlistBean flistBean : users.getFlist()) {
                if (flistBean.getUid().equals(userId)) {
                    String url = flistBean.getImgurl();
                    if (url == null) {
                        url = Constant.path;
                    }
                    return new UserInfo(flistBean.getUid()
                            , flistBean.getUname(),
                            Uri.parse(url));
                }
            }
        }

        return new UserInfo(users.getSinfo().getUid()
                , users.getSinfo().getUname(),
                Uri.parse(users.getSinfo().getImgurl()));
    }

}
